n, m = map(int, input().split())
board = []
for _ in range(n):
    board.append(list(map(int, input().split())))
# 二维前缀和
prefix = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, m + 1):
        prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + board[i - 1][j - 1]
# 一维前缀和 分别求列与行
prefix_c = [0] * (n + 1)  # 第i行的前缀和
prefix_r = [0] * (m + 1)  # 第j列的前缀和
for i in range(1, n + 1):
    prefix_c[i] = prefix_c[i - 1] + sum(board[i - 1])
for j in range(1, m + 1):
    row_sum = 0  # 要先计算列的和
    for k in range(n):
        row_sum += board[k][j - 1]
    prefix_r[j] = prefix_r[j - 1] + row_sum
result = -float('inf')
for start_i in range(1, n - 1):
    for end_i in range(start_i, n - 1):
        for start_j in range(1, m - 1):
            for end_j in range(start_j, m - 1):
                # 计算当前十字的大小
                ten = prefix_c[end_i + 1] - prefix_c[start_i]
                ten += prefix_r[end_j + 1] - prefix_r[start_j]

                a, b, c, d = start_i, start_j, end_i, end_j
                cross = prefix[c + 1][d + 1] - prefix[a][d + 1] - prefix[c + 1][b] + prefix[a][b]
                ten -= cross
                result = max(result, ten)
print(result)
